package com.dfbz.controller;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;

public class BaseController extends HttpServlet {

    protected String getUserId(HttpServletRequest req){
        // 获取当前登录的用户ID
        return req.getSession().getAttribute("myUserId").toString();
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) {

        try {
            String uri = req.getRequestURI();
            String funName = uri.substring(uri.lastIndexOf("/") + 1);
            Class<? extends BaseController> aClass = this.getClass();
            Method method = aClass.getDeclaredMethod(funName, HttpServletRequest.class, HttpServletResponse.class);
            method.invoke(aClass.newInstance(), req, resp);
        } catch (Exception e) {

        }


    }
}
